home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-25 | 6.3 KB | 170 lines | [TEXT/PJMM] |
- { Tools Plus Tutorial - - Picture Buttons }
-
- { NOTE: }
- { The MWERKS compiler directived ($IFC MWERKS) indicates code that is compiled only by }
- { the CodeWarrior compiler. THINK Pascal and Metrowerks CodeWarrior Pascal have }
- { _slight_ differences, and this compiler directive lets you use one source for both compilers. }
- { You can remove the code that does not pertain to your compiler. }
-
-
- program Tutorial;
- uses
- {$IFC MWERKS}
- Dialogs, Fonts, Processes, SegLoad, TextEdit, ToolsPlus, Windows;
- {$ELSEC}
- ToolsPlus;
- {$ENDC}
-
-
- const
- { Constants for picture buttons (for more readable code)… }
- LeftAlignButton = 3;
- CenterAlignButton = 4;
- RightAlignButton = 5;
- JustifyButton = 6;
- CutButton = 7;
- BucketButton = 8;
- ClipboardButton = 9;
- PrinterButton = 12;
- ModemButton = 13;
- ScrollingButton = 15;
- PowerButton = 23;
- DoneButton = 25;
-
- { Constants for picture button images (for more readable code)… }
- PrinterIcon = 150;
- ModemIcon = 151;
- LeftAlignIcon = 408;
- CenterAlignIcon = 409;
- RightAlignIcon = 410;
- JustifyIcon = 411;
- CutIcon = 412;
- BucketIcon = 413;
- ClipboardIcon = 414;
- PowerIcon = 450;
- ScrollingIcon = 458;
- DoneIcon = 464;
-
-
- var
- Poll: TPPollRecord; {Polling record to retrieve event information}
- ExitTheDemo: boolean; {Should the demo terminate?}
-
- theButton: integer; {Button counter }
-
-
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- procedure ApplicationInitialization;
- const
- DemoWindow1 = 1;
- DemoWindow2 = 2;
-
- { This big 3D button stays down when selected, lightens when selected,}
- { and gets whited out when disabled… }
- Big3Dspec = picbutLockSelected + picbutBigSICN3D + picbutSelectLightenSICN3D + picbutDimUsingWhite;
-
- { This small 3D button pops back up after being selected, lightens when }
- { selected, and gets whited out when disabled… }
- Small3Dspec = picbutSelectLightenSICN3D + picbutDimUsingWhite;
-
- { This ordinary icon (printer and modem) is selected when the mouse-down occurs, }
- { stays down when selected, darkens when selected. When disabled, a white }
- { screen effect is used and the border is preserved… }
- OrdinaryIconSpec = picbutInstantEvent + picbutLockSelected + picbutSelectDarken + picbutDimUsingWhite + picbutDimLeaveBorder;
-
- begin
- { Do all the application setup before you start polling for events… }
- AppleMenu('');
- Menu(1, 0, enabled, 'File');
- Menu(1, 1, enabled, 'Quit/Q');
- UpdateMenuBar;
-
-
- WindowOpen(DemoWindow1, 0, 0, 215, 160, 'Dummy Window', noGrowDocProc + wCenter, NoGoAway, NotModal);
- WindowOpen(DemoWindow2, 0, 0, 215, 160, 'Picture Buttons', noGrowDocProc + wTile, NoGoAway, NotModal);
-
- NewPictButton(LeftAlignButton, 12, 8, LeftAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(CenterAlignButton, 35, 8, CenterAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(RightAlignButton, 58, 8, RightAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(JustifyButton, 81, 8, JustifyIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
-
- NewPictButton(CutButton, 128, 9, CutIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(BucketButton, 151, 9, BucketIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(ClipboardButton, 174, 9, ClipboardIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
-
- NewPictButton(PrinterButton, 22, 50, PrinterIcon, OrdinaryIconSpec, enabled, selected, 0, 0, 0);
- NewPictButton(ModemButton, 63, 50, ModemIcon, OrdinaryIconSpec, enabled, notSelected, 0, 0, 0);
-
- {This is a dual state button (Power-On, Power-Off), so it is considered to be a "Multi-Stage" button (Off=0, 1=On).}
- { The button's value changes automatically when selected by the user. The values 'wrap' to allow 1 (on) to }
- { start back at 0 (off) again. An alternate icon is used to depict the selected button (down position), and }
- { disabled button for maximum visual control… }
- NewPictButton(PowerButton, 131, 50, PowerIcon, picbutMultiStage + picbutAutoValueChg + picbutValueWrap + picbutSelectAltImage + picbutDimAltImage, enabled, notSelected, 0, 0, 1);
-
- {This scrolling button has nine icon images in its SICN resource. It keeps producing doPictButton events while }
- { the mouse is held down. The button's value changes automatically with the top 1/2 of the button }
- { incrementing the value and the bottom 1/2 decrementing it. This is a BIG 3D button that looks 'pushed' when}
- { selected (not darker or ligher)… }
- NewPictButton(ScrollingButton, 172, 55, ScrollingIcon, picbutRepeatEvents + picbutAutoValueChg + picbutTopBottomSplit + picbutBigSICN3D + picbutSelectPushedSICN3D, enabled, notSelected, 1, 5, 9);
-
- {This is a really simple push-button that uses an alternate icon when the button is selected. }
- { When disabled, a white screen is overlayed and the border is preserved. }
- NewPictButton(DoneButton, 131, 130, DoneIcon, picbutSelectAltImage + picbutDimUsingWhite + picbutDimLeaveBorder, enabled, notSelected, 0, 0, 0);
-
- ExitTheDemo := false;
- end;
-
-
- { - - - - - - - - - - - - - - - - - - - - - - - - - - - }
- begin
- {$IFC MWERKS}
- {Toolbox initialization - - Done automatically by THINK Pascal}
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- MaxApplZone;
- {$ENDC}
-
- if not InitToolsPlus(0, 2, UseColor) then
- ExitToShell;
-
- ApplicationInitialization;
-
- while not ExitTheDemo do {Main Event Loop}
- if PollSystem(Poll) then {If an event is available, process the event…}
-
- case Poll.What of
-
- doPictButton:
- case Poll.Button.Num of
-
- LeftAlignButton, CenterAlignButton, RightAlignButton, JustifyButton:
- { Cycle through the group and turn off the buttons that weren't clicked (deselect them)…}
- for theButton := LeftAlignButton to JustifyButton do
- SelectPictButton(theButton, theButton = Poll.Button.Num);
-
- PrinterButton, ModemButton:
- { Cycle through the group and turn off the buttons that weren't clicked (deselect them)…}
- for theButton := PrinterButton to ModemButton do
- SelectPictButton(theButton, theButton = Poll.Button.Num);
-
- DoneButton:
- ExitTheDemo := true;
-
- otherwise {Ignore all other buttons}
- end;
-
- doMenu: {The only menu item available is 'Quit'…}
- ExitTheDemo := true;
-
- doChgWindow: {Activate the clicked window… }
- ActivateWindow(Poll.Window);
-
- otherwise {All other events are ignored}
- end
- end.